#include "barrier.h"


double barrier_function(double *x, NLPProblem *problem, double mu) {
    double sum = 0.0;
    double *g_val = (double *)malloc(problem->m * sizeof(double));
    
    if (g_val == NULL) {
        // 处理内存分配失败
        return INFINITY;
    }
    
    problem->g(x, g_val);
    for (int i = 0; i < problem->m; i++) {
        if (g_val[i] <= 0) {
            free(g_val);
            return INFINITY; // 不可行点
        }
        sum += log(g_val[i]);
    }
    
    free(g_val);
    return problem->f(x) - mu * sum;
}